/*
 * SignRuleItemAdapter.java
 * business
 *
 * Created by SunDing on 2016/12/28.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.response.SignInfoResponse;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

/**
 * 抽奖获奖名单
 */
public class SignRuleItemAdapter
        extends RecyclerView.Adapter<SignRuleItemAdapter.ViewHolder> {

    private List<SignInfoResponse.WinnerBean> mWinners;

    public void setData(List<SignInfoResponse.WinnerBean> winners) {
        mWinners = winners;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_sign_in_rule_item, parent, false);
        return new ViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        SignInfoResponse.WinnerBean winner = mWinners.get(position);
        holder.mTvShop.setText(
                UIUtils.getString(R.string.sign_congratulations, winner.getUserInfo()));
        holder.mTvPrize.setText(winner.getPrize());
    }

    @Override
    public int getItemCount() {
        return mWinners == null ? 0 : mWinners.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView mTvShop;
        private TextView mTvPrize;

        private ViewHolder(View itemView) {
            super(itemView);
            mTvShop = (TextView) itemView.findViewById(R.id.tv_shop);
            mTvPrize = (TextView) itemView.findViewById(R.id.tv_prize);
        }
    }
}
